layui.config({
    base : "../../js/"
}).extend({
    "jqCommon" : "jqCommon"
})
layui.use(['form','layer','jqCommon'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
        jqcommon = layui.jqCommon;

    form.on("submit(updateVip)",function(data){
        var vipId = $(".id").val();
        var month = $(".month").val();
        if(vipId == 1){
            month = 0;
        }
        var type = $(".type").val();
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            type: "PUT",
            url:  "http://mini.yantaibaixing.cn/vips",
            data: {"id":vipId,"name":$(".name").val(),"amount":$(".amount").val() * 100,"month":month},
            dataType: "JSON",
            success: function (data) {
                if(data.success){
                    setTimeout(function(){
                        top.layer.close(index);
                        top.layer.msg("修改会员信息成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    },2000);
                }
            }
        });
        return false;
    })

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})